<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加IP白名单</title>
    <link rel="stylesheet" type="text/css" href="/static/h+/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/font-awesome.min93e3.css?v=4.4.0">
    <!-- Data Tables -->
    <link rel="stylesheet" type="text/css" href="/static/select2/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/style.min.css?v=4.1.0">
    <link rel="stylesheet" type="text/css" href="/static/layer/skin/layer.css">
    <style type="text/css">
        .form-control{width: 200px;}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加IP白名单</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" onsubmit="return false">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">登录账号</label>
                            <div class="col-sm-10">
                                <select class="form-control" id="username">
                                    <option value="">请选择账号</option>
                                    {foreach $list as $item}
                                    <option value="{$item.username}">{$item.username}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">IP地址</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="ip">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <input class="btn btn-primary" type="button" data-action="save" value="保存内容">
                                <input class="btn btn-white" type="button" data-action="cancel" value="返回">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="/static/h+/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/select2/js/select2.min.js"></script>
<script type="text/javascript" src="/static/layer/layer.js"></script>
<script type="text/javascript">
    $(function(){
        $('#username').select2()
        $('#ip').focus()
        $(document).keydown(function(e){
            if (e.keyCode == 13) {
                $('input[data-action="save"]').click()
            }
        })
        $('input[data-action]').click(function(){
            $action = $(this).data('action');
            if ($action == 'cancel') {
                location.href = '/admin/ips';
            }else if ($action == 'save') {
                var ip = $('#ip');
                if (ip.val() == '') {
                    layer.msg('IP不能为空', {icon: 5, time: 1000}, function(){
                        ip.focus();
                    });
                    return false;
                }
                $.ajax({
                    type: 'post', cache: false, dataType: 'json',
                    url: '/admin/addip',
                    data: {'ip': ip.val(), 'username': $('#username').val()},
                    success: function(data){
                        if (data.status == 0) {
                            layer.confirm(data.info + '<br />是否继续添加？', {
                                btn: ['是', '否'],
                                shade: false,
                                closeBtn: 0
                            }, function(){
                                location.reload();
                            }, function(){
                                location.href = '/admin/ips'
                            });
                        }else{
                            layer.msg(data.info, {icon: 5, time: 1000});
                        }
                    }
                });
            }
        });
    });
</script>
</html>